package com.ruoyi.project.device.device.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.device.device.domain.BasDevice;
import com.ruoyi.project.device.device.service.IBasDeviceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备保养记录Controller
 * 
 * @author wld
 * @date 2023-04-04
 */
@Controller
@RequestMapping("/device/device")
public class BasDeviceController extends BaseController
{
    private String prefix = "device/device";

    @Autowired
    private IBasDeviceService basDeviceConserveService;

    @GetMapping()
    public String conserve()
    {
        return prefix + "/device";
    }

    /**
     * 查询设备
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasDevice basDeviceConserve)
    {
        startPage();
        List<BasDevice> list = basDeviceConserveService.selectBasDeviceConserveList(basDeviceConserve);
        return getDataTable(list);
    }

    /**
     * 导出设备
     */
    @Log(title = "导出设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BasDevice basDeviceConserve)
    {
        List<BasDevice> list = basDeviceConserveService.selectBasDeviceConserveList(basDeviceConserve);
        ExcelUtil<BasDevice> util = new ExcelUtil<BasDevice>(BasDevice.class);
        return util.exportExcel(list, "设备保养记录数据");
    }

    /**
     * 新增设备
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备
     * */
    @Log(title = "新增设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasDevice basDeviceConserve)
    {
        return toAjax(basDeviceConserveService.insertBasDeviceConserve(basDeviceConserve));
    }

    /**
     * 修改设备
     */
    @GetMapping("/edit/{deviceId}")
    public String edit(@PathVariable("deviceId") String deviceId, ModelMap mmap)
    {
        BasDevice basDeviceConserve = basDeviceConserveService.selectBasDeviceConserveByDeviceId(deviceId);
        mmap.put("basDeviceConserve", basDeviceConserve);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备
     */
    @Log(title = "修改保存设备", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BasDevice basDeviceConserve)
    {
        return toAjax(basDeviceConserveService.updateBasDeviceConserve(basDeviceConserve));
    }

    /**
     * 删除设备
     */
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basDeviceConserveService.deleteBasDeviceConserveByDeviceIds(ids));
    }
}
